package com.sisyphus.simple;

import android.app.Application;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.view.Window;


import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.constant.SpinnerStyle;
import com.sisyphus.mock.MockApplicationServer;
import com.sisyphus.spinach.ui.configs.ActivityConfigRegister;

public class App extends Application {

    static {

        SmartRefreshLayout.setDefaultRefreshInitializer((context, layout) ->
                layout.setReboundDuration(300)
                        .setEnableAutoLoadMore(true)
                        .setDragRate(0.4f)
                        .setEnableOverScrollBounce(true)
                        .setDisableContentWhenLoading(false)
        );

        SmartRefreshLayout.setDefaultRefreshHeaderCreator((context, layout) ->
                new ClassicsHeader(context)
                        .setTextSizeTitle(12)
                        .setEnableLastTime(false)
                        .setDrawableSize(15)
                        .setDrawableMarginRight(6)
                        .setSpinnerStyle(SpinnerStyle.Translate)
                        .setFinishDuration(500));

        SmartRefreshLayout.setDefaultRefreshFooterCreator((context, layout) ->
                new ClassicsFooter(context).setTextSizeTitle(12)
                        .setFinishDuration(500)
                        .setDrawableSize(15)
                        .setDrawableMarginRight(8)
                        .setSpinnerStyle(SpinnerStyle.Translate));
    }


    @Override
    public void onCreate() {
        super.onCreate();

        MockApplicationServer.startServer(this);

        registerActivityLifecycleCallbacks(new ActivityConfigRegister(activity -> {
            // 垂直方向
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);

            // 背景颜色
            Window window = activity.getWindow();
            window.getDecorView().setBackgroundColor(Color.WHITE);

            // ...

        }));
    }

}
